<template>
	<div class="app-container">
		<el-table v-loading="loading" :data="shopList">
			<el-table-column label="排名" align="center" type="index" />
			<el-table-column label="商户名称" align="center" prop="shopName" />
			<el-table-column label="经营区域" align="center" prop="shopArea" />
			<el-table-column label="负责人" align="center" prop="perName" />
			<el-table-column label="平均星级" align="center" prop="star" width="180">
				<template slot-scope="scope">
					<el-rate disabled v-model="scope.row.star"></el-rate>
				</template>
			</el-table-column>
		</el-table>
		<pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
			@pagination="getList" />
	</div>
</template>

<script>
	import {
		listShopByStar
	} from "../../../api/shop/shop";
	import {
		listShop,
		getShop,
		delShop,
		addShop,
		updateShop
	} from "@/api/shop/shop";

	export default {
		name: "Shop",
		dicts: ['shop_audit'],
		data() {
			return {
				// 遮罩层
				loading: true,
				// 选中数组
				ids: [],
				// 非单个禁用
				single: true,
				// 非多个禁用
				multiple: true,
				// 显示搜索条件
				showSearch: true,
				// 总条数
				total: 0,
				// 门店管理表格数据
				shopList: [],
				// 弹出层标题
				title: "",
				// 是否显示弹出层
				open: false,
				openShenHe: false,
				// 查询参数
				queryParams: {
					pageNum: 1,
					pageSize: 10,
					shopName: null,
					shopAudit: null,
				},
				// 表单参数
				form: {},
				// 表单校验
				rules: {

				}
			};
		},
		created() {
			this.getList();
		},
		methods: {
			/** 查询门店管理列表 */
			getList() {
				this.loading = true;
				listShopByStar(this.queryParams).then(response => {
					this.shopList = response.rows;
					this.total = response.total;
					this.loading = false;
				});
			},
			// 取消按钮
			cancel() {
				this.open = false;
				this.reset();
			},
			cancelShenHe() {
				this.openShenHe = false;
				this.reset();
			},
			// 表单重置
			reset() {
				this.form = {
					shopId: null,
					shopName: null,
					shopNumber: null,
					shopArea: null,
					shopAddress: null,
					shopIntro: null,
					shopAudit: null,
					shopCreateTime: null,
					shopLicence: null,
					cardFront: null,
					cardBack: null,
					shopMoney: null,
					accIncome: null,
					accOut: null,
					perName: null,
					perPhone: null,
					perPassword: null,
					perIdcard: null,
					storeName: null,
					week: null,
					startTime: null,
					endTime: null,
					longitude: null,
					latitude: null,
					star: null,
					sales: null
				};
				this.resetForm("form");
			},
			/** 搜索按钮操作 */
			handleQuery() {
				this.queryParams.pageNum = 1;
				this.getList();
			},
			/** 重置按钮操作 */
			resetQuery() {
				this.resetForm("queryForm");
				this.handleQuery();
			},
			// 多选框选中数据
			handleSelectionChange(selection) {
				this.ids = selection.map(item => item.shopId)
				this.single = selection.length !== 1
				this.multiple = !selection.length
			},
			/** 新增按钮操作 */
			handleAdd() {
				this.reset();
				this.open = true;
				this.title = "添加门店管理";
			},
			/** 修改按钮操作 */
			handleUpdate(row) {
				this.reset();
				const shopId = row.shopId || this.ids
				getShop(shopId).then(response => {
					this.form = response.data;
					this.open = true;
					this.title = "详情";
				});
			},
			shenHe(row) {
				this.reset();
				const shopId = row.shopId || this.ids
				getShop(shopId).then(response => {
					this.form = response.data;
					this.openShenHe = true;
					this.title = "审核";
				});
			},
			/** 提交按钮 */
			submitForm() {
				this.$refs["form"].validate(valid => {
					if (valid) {
						if (this.form.shopId != null) {
							updateShop(this.form).then(response => {
								this.$modal.msgSuccess("修改成功");
								this.open = false;
								this.getList();
							});
						} else {
							addShop(this.form).then(response => {
								this.$modal.msgSuccess("新增成功");
								this.open = false;
								this.getList();
							});
						}
					}
				});
			},
			submitFormShenHe() {
				this.$refs["form"].validate(valid => {
					if (valid) {
						if (this.form.shopId != null) {
							updateShop(this.form).then(response => {
								this.$modal.msgSuccess("修改成功");
								this.ShenHe = false;
								this.getList();
							});
						} else {
							addShop(this.form).then(response => {
								this.$modal.msgSuccess("新增成功");
								this.ShenHe = false;
								this.getList();
							});
						}
					}
				});
			},
			/** 删除按钮操作 */
			handleDelete(row) {
				const shopIds = row.shopId || this.ids;
				this.$modal.confirm('是否确认删除门店管理编号为"' + shopIds + '"的数据项？').then(function() {
					return delShop(shopIds);
				}).then(() => {
					this.getList();
					this.$modal.msgSuccess("删除成功");
				}).catch(() => {});
			},
			/** 导出按钮操作 */
			handleExport() {
				this.download('shop/shop/export', {
					...this.queryParams
				}, `shop_${new Date().getTime()}.xlsx`)
			}
		}
	};
</script>
<style scoped>

</style>